<?php
/**
 * IMMOPHP ADMINISTRATION
 * 
 */
$debut_g = microtime(true);     // Chrono des pages pour mod debug
session_start();                // Debut des sessions

# SECURISATION FORMULAIRE
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if ($_SERVER['HTTP_REFERER'] != "")
{
if (!preg_match('/' . $_SERVER['HTTP_HOST'] . '/', $_SERVER['HTTP_REFERER'])) die("<br /><br /><br /><div style=\"text-align: center;\"><big>Error : you can't submit request from another server !</big></div>");
}
else
{
die("<br /><br /><br /><div style=\"text-align: center;\"><big>Error : Referer not found ! Check your browser or firewall's settings.</big></div>");
}
}

// Dertermination de IMMOPHP_ROOT_PATH
$path_common = __FILE__;
$path_common = str_replace('administration'. DIRECTORY_SEPARATOR .'kernel'. DIRECTORY_SEPARATOR .'common.php','',$path_common);
define('IMMOPHP_ROOT_PATH', $path_common);                                              // Depuis le front
define('IMMOPHP_ADMIN_ROOT_PATH',dirname(dirname(__FILE__)). DIRECTORY_SEPARATOR);      // Depuis le back

// Appel des fichiers
require_once IMMOPHP_ROOT_PATH . 'conf/config.php';
require_once IMMOPHP_ROOT_PATH . 'conf/main.file.dist.php';
//require_once IMMOPHP_ROOT_PATH . 'kernel/db/class_mysql.php';
require_once IMMOPHP_ROOT_PATH.'kernel/db/class_PDO_mysql.php';
require_once IMMOPHP_ROOT_PATH . 'kernel/db/Query.function.php';
require_once IMMOPHP_ROOT_PATH . 'kernel/includes/functions.php';
require_once IMMOPHP_ROOT_PATH . 'kernel/includes/template.php';
require_once IMMOPHP_ROOT_PATH . 'kernel/class/Immophp.class.php';
require_once IMMOPHP_ROOT_PATH . 'kernel/lang/fr.php';
require_once IMMOPHP_ROOT_PATH . 'kernel/includes/ps_pagination.php';
require_once IMMOPHP_ADMIN_ROOT_PATH . 'kernel/Session.class.php';
require_once IMMOPHP_ADMIN_ROOT_PATH . 'kernel/Annonce.class.php';
require_once IMMOPHP_ADMIN_ROOT_PATH . 'kernel/function_admin.php';
require_once IMMOPHP_ADMIN_ROOT_PATH . 'kernel/Immophp_adm.class.php';
require_once IMMOPHP_ADMIN_ROOT_PATH . 'kernel/Menu.class.php';
require_once IMMOPHP_ADMIN_ROOT_PATH . 'kernel/lang/fr.php';
require_once IMMOPHP_ROOT_PATH . 'kernel/includes/smarty.php';                              // Appel fichier de smarty
$smarty->template_dir = IMMOPHP_ADMIN_ROOT_PATH . 'template';                               // Chemin par defaut d appel des templates
require_once IMMOPHP_ROOT_PATH . 'kernel/includes/Lite.php';                                // Appel cache lite (PEAR)
$cache = new Cache_Lite(array(
    'cacheDir' => IMMOPHP_ROOT_PATH . 'cache/',
    'lifeTime'  =>  600,
));
require_once IMMOPHP_ROOT_PATH . 'kernel/class/Manager.class.php';

$s = $cache->get('setting_immophp');

$setting = array();

// Declaration des class
//$template = new template('.');
$db = new db_sql();
$db->sql_connect($basesql);
$Menu = new Menu();
$Session = new session($db);
$type_array = get_type_array();

$GLOBALS['db'] = $db;
$GLOBALS['smarty'] = $smarty;
$GLOBALS['session'] = $Session;
$GLOBALS['cache']   = $cache;

$Session->delete_session_time();


$paramClass = array('db' => $db, 'lang' => $lang, 'session' => $Session, 'cache' => $cache, 'smarty' => $smarty);
$Immophp = new immophp($paramClass);
$Manager = new Manager($paramClass);
    
$setting = $Immophp->setting;

$cp = get_currentpage();
if($cp != 'identification.php' && $cp != 'logout.php')
{
	if(!$Session->check())
		redirect('identification.php');	
}

require_once IMMOPHP_ADMIN_ROOT_PATH .'kernel/header.php';
?>